package dql.com.ordsystem;

import java.util.ArrayList;
import java.util.Iterator;


import dql.com.ordsystem.OrderItemAdapt.ViewHolder;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.format.Time;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class Lunch extends Activity {

	private ListView lv; // ListBox of ordered Items
	private ArrayList<String> order=new ArrayList<String>(); // ordered Items from table
	private ArrayList<String> price=new ArrayList<String>();
	private Table table; // global variant of table
	private OrderItemAdapt oia; // the adapt of the ListView
	private LayoutInflater inflater;
	private LinearLayout lin;
	private ArrayList<String> softdrinks;
	private ArrayList<String> drinkslist=new ArrayList<String>();
	private ArrayList<String> saftdrinks;
	private ArrayList<String> waterdrinks;
	private ArrayList<String> beerdrinks;
	private ArrayList<String> hotdrinks;
	private ArrayList<String> salats;
	private ArrayList<String> bakes;
	private ArrayList<String> fries;
	private ArrayList<String> sushis;
	private ArrayList<String> ramens;
	private ArrayList<String> sake;
	private ArrayList<String> wein;
	private Item it;
	
	@Override
	protected void onStart() {
	    super.onStart();  // Always call the superclass method first
	    table = (Table) getApplicationContext();
	    if(table.getNum().equals(""))
	    {
	    	Intent intent =new Intent(this, MainActivity.class);
			startActivity(intent);
	    }
	    
	
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lunch);
		inflater = getLayoutInflater();
		lin = (LinearLayout) findViewById(R.id.setlunchview);
		table = (Table) getApplicationContext();
		it = new Item(getApplicationContext());

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		// getMenuInflater().inflate(R.menu.activity_try_lay_out, menu);
		return true;
	}
	
	public boolean isLaunch(){
		
		Time t1 = new Time();
		Time t2=new Time();
		t1.setToNow();
		t2.setToNow();
		t2.hour=14;
		t2.minute=0;
		if(t1.before(t2)){
			return true;
		} else {
			return true;
		}
		
	}

	public void goRice(View view) {

		if(this.isLaunch()){
		
		ScrollView layout = (ScrollView) inflater.inflate(R.layout.rice, null)
				.findViewById(R.id.riceview);
		
		lin.removeAllViews();
		lin.addView(layout);
		}else{
			Toast.makeText(getApplicationContext(), "not launch time", Toast.LENGTH_LONG).show();
		}

	}
//	
//	public void goSushi(View view) {
//
//		if(this.isLaunch()){
//		
//		ScrollView layout = (ScrollView) inflater.inflate(R.layout.sushi, null)
//				.findViewById(R.id.sushiview);
//		
//		lin.removeAllViews();
//		lin.addView(layout);
//		}else{
//			Toast.makeText(getApplicationContext(), "not launch time", Toast.LENGTH_LONG).show();
//		}
//
//	}
//	
//	public void goVeg(View view) {
//
//		if(this.isLaunch()){
//		
//		ScrollView layout = (ScrollView) inflater.inflate(R.layout.veg, null)
//				.findViewById(R.id.vegview);
//		
//		lin.removeAllViews();
//		lin.addView(layout);
//		}else{
//			Toast.makeText(getApplicationContext(), "not launch time", Toast.LENGTH_LONG).show();
//		}
//
//	}
	
	public void goRamen(View view) {

		if(this.isLaunch()){
		
		ScrollView layout = (ScrollView) inflater.inflate(R.layout.ramen, null)
				.findViewById(R.id.ramenview);
		
		lin.removeAllViews();
		lin.addView(layout);
		}else{
			Toast.makeText(getApplicationContext(), "not launch time", Toast.LENGTH_LONG).show();
		}

	}
	
	
//	public void goDon(View view) {
//
//		if(this.isLaunch()){
//		
//		ScrollView layout = (ScrollView) inflater.inflate(R.layout.don, null)
//				.findViewById(R.id.donview);
//		
//		lin.removeAllViews();
//		lin.addView(layout);
//		}else{
//			Toast.makeText(getApplicationContext(), "not launch time", Toast.LENGTH_LONG).show();
//		}
//
//	}
//	
//	public void goUdon(View view) {
//
//		if(this.isLaunch()){
//		
//		ScrollView layout = (ScrollView) inflater.inflate(R.layout.udon, null)
//				.findViewById(R.id.udonview);
//		
//		lin.removeAllViews();
//		lin.addView(layout);
//		}else{
//			Toast.makeText(getApplicationContext(), "not launch time", Toast.LENGTH_LONG).show();
//		}
//
//	}

	public void onDelete(View view) {

		for (int i = 0; i < lv.getCount(); i++) {
			if (OrderItemAdapt.getIsSelected().get(i)) {
				Log.i("------", Integer.toString(i));
				String s = OrderItemAdapt.getlist().get(i);
				String s2 = OrderItemAdapt.getlist2().get(i);
				Log.i("xxxxxxxx", s);
				order.remove(s);
				price.remove(s2);
			}
		}
		Log.i("yyyyyyyyyy", Integer.toString(order.size()));
		oia = new OrderItemAdapt(order, price,this);
		lv.setAdapter(oia);
		Toast.makeText(getApplicationContext(),
				"you have " + table.getOrder().size() + " items in your car",
				Toast.LENGTH_SHORT).show();

	}

	public void goSoftDrink(View View) {
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.activity_drink, null).findViewById(R.id.drink);
		lin.removeAllViews();
		lin.addView(layout);
		ListView drinklist = (ListView) findViewById(R.id.drinklist);
		softdrinks = it.getAllSoftDrink();
		drinkslist.clear();
		for(String s:softdrinks){
			drinkslist.add(s+"   "+it.getPrice(s));
		}
		drinkslist.add("1 Coffeinhaltig 2 mit Farbstoff 3 Suessungsmitteln 4 mit Antioxidotionsmittel 5 enthaelt eine Phenylalaninquelle");
		drinklist.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, drinkslist));
		drinklist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long id) {
				if(position!=softdrinks.size()){
				table.addOrder(softdrinks.get(position));
				table.getPrices().add(it.getPrice(softdrinks.get(position)));
				Toast.makeText(getApplicationContext(),
						softdrinks.get(position) + " is added to you car",
						Toast.LENGTH_SHORT).show();

			}
				}

		});
	}
	
	public void goSaftDrink(View View) {
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.activity_drink, null).findViewById(R.id.drink);
		lin.removeAllViews();
		lin.addView(layout);
		ListView drinklist = (ListView) findViewById(R.id.drinklist);
		saftdrinks = it.getAllSaftDrink();
		drinkslist.clear();
		for(String s:saftdrinks){
			drinkslist.add(s+"   "+it.getPrice(s));
		}
		drinklist.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, drinkslist));
		drinklist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long id) {
				table.addOrder(saftdrinks.get(position));
				table.getPrices().add(it.getPrice(saftdrinks.get(position)));
				Toast.makeText(getApplicationContext(),
						saftdrinks.get(position) + " is added to you car",
						Toast.LENGTH_SHORT).show();

			}

		});
	}
	
	public void goWaterDrink(View View) {
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.activity_drink, null).findViewById(R.id.drink);
		lin.removeAllViews();
		lin.addView(layout);
		ListView drinklist = (ListView) findViewById(R.id.drinklist);
		waterdrinks = it.getAllWaterDrink();
		drinkslist.clear();
		for(String s:waterdrinks){
			drinkslist.add(s+"   "+it.getPrice(s));
		}
		drinklist.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, drinkslist));
		drinklist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long id) {
				table.addOrder(waterdrinks.get(position));
				table.getPrices().add(it.getPrice(waterdrinks.get(position)));
				Toast.makeText(getApplicationContext(),
						waterdrinks.get(position) + " is added to you car",
						Toast.LENGTH_SHORT).show();

			}

		});
	}
	
	public void goBeerDrink(View View) {
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.activity_drink, null).findViewById(R.id.drink);
		lin.removeAllViews();
		lin.addView(layout);
		ListView drinklist = (ListView) findViewById(R.id.drinklist);
		beerdrinks = it.getAllBeerDrink();
		drinkslist.clear();
		for(String s:beerdrinks){
			drinkslist.add(s+"   "+it.getPrice(s));
		}
		drinklist.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, drinkslist));
		drinklist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long id) {
				table.addOrder(beerdrinks.get(position));
				table.getPrices().add(it.getPrice(beerdrinks.get(position)));
				Toast.makeText(getApplicationContext(),
						beerdrinks.get(position) + " is added to you car",
						Toast.LENGTH_SHORT).show();

			}

		});
	}
	
	public void goHotDrink(View View) {
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.activity_drink, null).findViewById(R.id.drink);
		lin.removeAllViews();
		lin.addView(layout);
		ListView drinklist = (ListView) findViewById(R.id.drinklist);
		hotdrinks = it.getAllHotDrink();
		drinkslist.clear();
		for(String s:hotdrinks){
			drinkslist.add(s+"   "+it.getPrice(s));
		}
		drinklist.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, drinkslist));
		drinklist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long id) {
				table.addOrder(hotdrinks.get(position));
				table.getPrices().add(it.getPrice(hotdrinks.get(position)));
				Toast.makeText(getApplicationContext(),
						hotdrinks.get(position) + " is added to you car",
						Toast.LENGTH_SHORT).show();

			}

		});
	}
	
	public void goSalat(View View) {
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.activity_drink, null).findViewById(R.id.drink);
		lin.removeAllViews();
		lin.addView(layout);
		ListView drinklist = (ListView) findViewById(R.id.drinklist);
		salats = it.getSalat();
		drinkslist.clear();
		for(String s:salats){
			drinkslist.add(s+"   "+it.getPrice(s));
		}
		drinklist.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, drinkslist));
		drinklist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long id) {
				table.addOrder(salats.get(position));
				table.getPrices().add(it.getPrice(salats.get(position)));
				Toast.makeText(getApplicationContext(),
						salats.get(position) + " is added to you car",
						Toast.LENGTH_SHORT).show();

			}

		});
	}
	public void goBake(View View) {
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.activity_drink, null).findViewById(R.id.drink);
		lin.removeAllViews();
		lin.addView(layout);
		ListView drinklist = (ListView) findViewById(R.id.drinklist);
		bakes = it.getBake();
		drinkslist.clear();
		for(String s:bakes){
			drinkslist.add(s+"   "+it.getPrice(s));
		}
		drinklist.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, drinkslist));
		drinklist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long id) {
				table.addOrder(bakes.get(position));
				table.getPrices().add(it.getPrice(bakes.get(position)));
				Toast.makeText(getApplicationContext(),
						bakes.get(position) + " is added to you car",
						Toast.LENGTH_SHORT).show();

			}

		});
	}
	
	public void goFry(View View) {
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.activity_drink, null).findViewById(R.id.drink);
		lin.removeAllViews();
		lin.addView(layout);
		ListView drinklist = (ListView) findViewById(R.id.drinklist);
		fries = it.getFry();
		drinkslist.clear();
		for(String s:fries){
			drinkslist.add(s+"   "+it.getPrice(s));
		}
		drinklist.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, drinkslist));
		drinklist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long id) {
				table.addOrder(fries.get(position));
				table.getPrices().add(it.getPrice(fries.get(position)));
				Toast.makeText(getApplicationContext(),
						fries.get(position) + " is added to you car",
						Toast.LENGTH_SHORT).show();

			}

		});
	}
	
	public void goSushi(View View) {
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.activity_drink, null).findViewById(R.id.drink);
		lin.removeAllViews();
		lin.addView(layout);
		ListView drinklist = (ListView) findViewById(R.id.drinklist);
		sushis = it.getSushi();
		drinkslist.clear();
		for(String s:sushis){
			drinkslist.add(s+"   "+it.getPrice(s));
		}
		drinklist.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, drinkslist));
		drinklist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long id) {
				table.addOrder(sushis.get(position));
				table.getPrices().add(it.getPrice(sushis.get(position)));
				Toast.makeText(getApplicationContext(),
						sushis.get(position) + " is added to you car",
						Toast.LENGTH_SHORT).show();

			}

		});
	}
	
	public void goWein(View View) {
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.activity_drink, null).findViewById(R.id.drink);
		lin.removeAllViews();
		lin.addView(layout);
		ListView drinklist = (ListView) findViewById(R.id.drinklist);
		wein = it.getWein();
		drinkslist.clear();
		for(String s:wein){
			drinkslist.add(s+"   "+it.getPrice(s));
		}
		drinklist.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, drinkslist));
		drinklist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long id) {
				table.addOrder(wein.get(position));
				table.getPrices().add(it.getPrice(wein.get(position)));
				Toast.makeText(getApplicationContext(),
						wein.get(position) + " is added to you car",
						Toast.LENGTH_SHORT).show();

			}

		});
	}
	
	public void goSake(View View) {
		LinearLayout layout = (LinearLayout) inflater.inflate(
				R.layout.activity_drink, null).findViewById(R.id.drink);
		lin.removeAllViews();
		lin.addView(layout);
		ListView drinklist = (ListView) findViewById(R.id.drinklist);
		sake = it.getSake();
		drinkslist.clear();
		for(String s:sake){
			drinkslist.add(s+"   "+it.getPrice(s));
		}
		drinklist.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, drinkslist));
		drinklist.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long id) {
				table.addOrder(sake.get(position));
				table.getPrices().add(it.getPrice(sake.get(position)));
				Toast.makeText(getApplicationContext(),
						sake.get(position) + " is added to you car",
						Toast.LENGTH_SHORT).show();

			}

		});
	}
	public void goShopCar(View view) {

		RelativeLayout layout = (RelativeLayout) inflater.inflate(
				R.layout.activity_my_car, null).findViewById(R.id.MyCar);
		lin.removeAllViews();
		lin.addView(layout);
		order = table.getOrder();
		price=table.getPrices();
		lv = (ListView) findViewById(R.id.mycarlist);
		// Toast.makeText(getApplicationContext(),
		// "M1 is added to you car"+table.getOrder().size(),
		// Toast.LENGTH_SHORT).show();
		oia = new OrderItemAdapt(order,price,this);
		lv.setAdapter(oia);
		lv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {

				// get the ViewHolder Object avoid through the findViewById to
				// get view
				ViewHolder holder = (ViewHolder) arg1.getTag();
				// toggle the checkbox
				holder.cb.toggle();
				// record the checkbox
				OrderItemAdapt.getIsSelected().put(arg2, holder.cb.isChecked());
			}
		});

	}

	public void oderRice(View view) {
		String order;
		switch (view.getId()) {
		case R.id.riceb1:
			order = this.getString(R.string.rice1);
			table.addOrder(order);
			table.getPrices().add(this.getString(R.string.rice1price));
			Toast.makeText(getApplicationContext(),
					order + " is added to you car", Toast.LENGTH_SHORT).show();
			break;
		case R.id.riceb2:
			order = this.getString(R.string.rice2);
			table.addOrder(order);
			table.getPrices().add(this.getString(R.string.rice2price));
			Toast.makeText(getApplicationContext(),
					order + " is added to you car", Toast.LENGTH_SHORT).show();
			break;
		case R.id.riceb3:
			order = this.getString(R.string.rice3);
			table.addOrder(order);
			table.getPrices().add(this.getString(R.string.rice3price));
			Toast.makeText(getApplicationContext(),
					order + " is added to you car", Toast.LENGTH_SHORT).show();
			break;
		case R.id.riceb4:
			order = this.getString(R.string.rice4);
			table.addOrder(order);
			table.getPrices().add(this.getString(R.string.rice4price));
			Toast.makeText(getApplicationContext(),
					order + " is added to you car", Toast.LENGTH_SHORT).show();
			break;
		case R.id.riceb5:
			order = this.getString(R.string.rice5);
			table.addOrder(order);
			table.getPrices().add(this.getString(R.string.rice5price));
			Toast.makeText(getApplicationContext(),
					order + " is added to you car", Toast.LENGTH_SHORT).show();
			break;
		case R.id.riceb6:
			order = this.getString(R.string.rice6);
			table.addOrder(order);
			table.getPrices().add(this.getString(R.string.rice6price));
			Toast.makeText(getApplicationContext(),
					order + " is added to you car", Toast.LENGTH_SHORT).show();
			break;
		case R.id.riceb7:
			order = this.getString(R.string.rice7);
			table.addOrder(order);
			table.getPrices().add(this.getString(R.string.rice7price));
			Toast.makeText(getApplicationContext(),
					order + " is added to you car", Toast.LENGTH_SHORT).show();
			break;
		default:
			break;

		}

	}
//	
//	public void oderSushi(View view) {
//		String order;
//		switch (view.getId()) {
//		case R.id.sushib1:
//			order = this.getString(R.string.sushi1);
//			table.addOrder(order);
//			table.getPrices().add(this.getString(R.string.sushi1price));
//			Toast.makeText(getApplicationContext(),
//					order + " is added to you car", Toast.LENGTH_SHORT).show();
//			break;
//		
//		default:
//			break;
//
//		}
//
//	}
	
	
//	public void oderVeg(View view) {
//		String order;
//		switch (view.getId()) {
//		case R.id.vegb1:
//			order = this.getString(R.string.veg1);
//			table.addOrder(order);
//			table.getPrices().add(this.getString(R.string.veg1price));
//			Toast.makeText(getApplicationContext(),
//					order + " is added to you car", Toast.LENGTH_SHORT).show();
//			break;
//		case R.id.vegb2:
//			order = this.getString(R.string.veg2);
//			table.addOrder(order);
//			table.getPrices().add(this.getString(R.string.veg2price));
//			Toast.makeText(getApplicationContext(),
//					order + " is added to you car", Toast.LENGTH_SHORT).show();
//			break;
//		case R.id.vegb3:
//			order = this.getString(R.string.veg3);
//			table.addOrder(order);
//			table.getPrices().add(this.getString(R.string.veg3price));
//			Toast.makeText(getApplicationContext(),
//					order + " is added to you car", Toast.LENGTH_SHORT).show();
//			break;
//		case R.id.vegb4:
//			order = this.getString(R.string.veg4);
//			table.addOrder(order);
//			table.getPrices().add(this.getString(R.string.veg4price));
//			Toast.makeText(getApplicationContext(),
//					order + " is added to you car", Toast.LENGTH_SHORT).show();
//			break;
//		default:
//			break;
//
//		}
//
//	}
	
	public void oderRamen(View view) {
		String order;
		switch (view.getId()) {
		case R.id.ramenb1:
			order = this.getString(R.string.ramen1);
			table.addOrder(order);
			table.getPrices().add(this.getString(R.string.ramen1price));
			Toast.makeText(getApplicationContext(),
					order + " is added to you car", Toast.LENGTH_SHORT).show();
			break;
		case R.id.ramenb2:
			order = this.getString(R.string.ramen2);
			table.addOrder(order);
			table.getPrices().add(this.getString(R.string.ramen2price));
			Toast.makeText(getApplicationContext(),
					order + " is added to you car", Toast.LENGTH_SHORT).show();
			break;
		case R.id.ramenb3:
			order = this.getString(R.string.ramen3);
			table.addOrder(order);
			table.getPrices().add(this.getString(R.string.ramen3price));
			Toast.makeText(getApplicationContext(),
					order + " is added to you car", Toast.LENGTH_SHORT).show();
			break;
		case R.id.ramenb4:
			order = this.getString(R.string.ramen4);
			table.addOrder(order);
			table.getPrices().add(this.getString(R.string.ramen4price));
			Toast.makeText(getApplicationContext(),
					order + " is added to you car", Toast.LENGTH_SHORT).show();
			break;
			
		case R.id.ramenb5:
			order = this.getString(R.string.ramen5);
			table.addOrder(order);
			table.getPrices().add(this.getString(R.string.ramen5price));
			Toast.makeText(getApplicationContext(),
					order + " is added to you car", Toast.LENGTH_SHORT).show();
			break;
		default:
			break;

		}

	}
	
//	public void oderDon(View view) {
//		String order;
//		switch (view.getId()) {
//		case R.id.donb1:
//			order = this.getString(R.string.don1);
//			table.addOrder(order);
//			table.getPrices().add(this.getString(R.string.don1price));
//			Toast.makeText(getApplicationContext(),
//					order + " is added to you car", Toast.LENGTH_SHORT).show();
//			break;
//		case R.id.donb2:
//			order = this.getString(R.string.don2);
//			table.addOrder(order);
//			table.getPrices().add(this.getString(R.string.don2price));
//			Toast.makeText(getApplicationContext(),
//					order + " is added to you car", Toast.LENGTH_SHORT).show();
//			break;
//		case R.id.donb3:
//			order = this.getString(R.string.don3);
//			table.addOrder(order);
//			table.getPrices().add(this.getString(R.string.don3price));
//			Toast.makeText(getApplicationContext(),
//					order + " is added to you car", Toast.LENGTH_SHORT).show();
//			break;
//	
//		default:
//			break;
//
//		}
//
//	}
//	
//	public void oderUdon(View view) {
//		String order;
//		switch (view.getId()) {
//		case R.id.udonb1:
//			order = this.getString(R.string.udon1);
//			table.addOrder(order);
//			table.getPrices().add(this.getString(R.string.udon1price));
//			Toast.makeText(getApplicationContext(),
//					order + " is added to you car", Toast.LENGTH_SHORT).show();
//			break;
//		case R.id.udonb2:
//			order = this.getString(R.string.udon2);
//			table.addOrder(order);
//			table.getPrices().add(this.getString(R.string.udon2price));
//			Toast.makeText(getApplicationContext(),
//					order + " is added to you car", Toast.LENGTH_SHORT).show();
//			break;
//		case R.id.udonb3:
//			order = this.getString(R.string.udon3);
//			table.addOrder(order);
//			
//			table.getPrices().add(this.getString(R.string.udon3price));
//			Toast.makeText(getApplicationContext(),
//					order + " is added to you car", Toast.LENGTH_SHORT).show();
//			break;
//	
//		default:
//			break;
//
//		}
//
//	}
	
	
	

	public void finishShopping(View view) {
		EditText code =(EditText)findViewById(R.id.codeinput);
		table.setCode(code.getText().toString());
		Log.e("---------", table.getCode());
		new MyAction().execute("add");

	}
	
	public void goService(View view) {
	
		new MyAction().execute("service");

	}
	public void payBill(View view) {
		new MyAction().execute("pay");

	}

	public void payBillCard(View view) {
		new MyAction().execute("paycard");

	}
	
	private class MyAction extends AsyncTask<String, Void, Boolean> {

		@Override
		protected Boolean doInBackground(String... params) {
			String url = getResources().getString(R.string.server);
			if (params[0].equals("add")) {

				String or = "";
				Log.e("---------", url);
				Iterator<String> it = order.iterator();
				while (it.hasNext()) {
					or = or + it.next() + ";";
					Log.e("---------", or);

				}

				return OrderManager.addOrder(url, table.getNum(), or,table.getCode());
			}
			if (params[0].equals("pay")) {
				Log.e("-------aaaa--", table.getNum());

				return OrderManager.payOrder(url, table.getNum());
			}
			
			if (params[0].equals("paycard")) {
				Log.e("-------aaaa--", table.getNum());

				return OrderManager.payOrderCard(url, table.getNum());
			}
			if (params[0].equals("service")) {
				Log.e("-------aaaa--", table.getNum());

				return OrderManager.service(url, table.getNum());
			}
			
			return false;

		}

		protected void onPostExecute(Boolean res) {
			if (res) {
				order.clear();
				price.clear();
				oia = new OrderItemAdapt(order, price,getApplicationContext());
				if(lv==null){
					Toast.makeText(getApplicationContext(), "please order first.",
							Toast.LENGTH_SHORT).show();
				}else {
				lv.setAdapter(oia);
				Toast.makeText(getApplicationContext(), "you order is sended",
						Toast.LENGTH_SHORT).show();
				}
				
			} else {
				Toast.makeText(getApplicationContext(), "Please try it again",
						Toast.LENGTH_SHORT).show();
			}

		}

	}
	
	
//	private class GetFoods extends AsyncTask<String, Void, String> {
//
//		@Override
//		protected String doInBackground(String... params) {
//			String url = getResources().getString(R.string.server);
//			if (params[0].equals("Ramens")) {
//				return OrderManager.getFoods(url,"R");
//			}		
//			return "";
//
//		}
//
//		protected void onPostExecute(String res) {
//			if(res.equals("")){
//				Toast.makeText(getApplicationContext(), "Please try it again",
//						Toast.LENGTH_SHORT).show();
//			}else{
//				for(String s:res.split(";")){
//				    ramens.add(s);	
//				}
//			}
//
//		}
//
//	}
	

}
